package com.ruoyi.web.controller.system.task;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.TBaseInfo;
import com.ruoyi.system.domain.dto.ConditionReq;
import com.ruoyi.system.domain.dto.TBaseInfoDto;
import com.ruoyi.system.domain.dto.TTaskInfoDto;
import com.ruoyi.system.service.TaskService;
import com.ruoyi.system.service.UserService;
import com.ruoyi.web.controller.common.RequestCheckUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api("任务相关")
@RestController
@RequestMapping("sys/task")
public class TTaskController {
    @Resource
    UserService userService;
    @Resource
    TaskService taskService;

    /**
     * 添加基础信息
     *
     * @param baseInfo
     * @return
     */
    @PostMapping("/addBaseInfo")
    public AjaxResult addBaseInfo(@RequestBody TBaseInfo baseInfo) {
        RequestCheckUtil.checkBaseInfoAdd(baseInfo);
        taskService.addBaseInfo(baseInfo);
        return AjaxResult.success();
    }


    @PostMapping("/updateBaseInfo")
    public AjaxResult updateBaseInfo(@RequestBody TBaseInfo baseInfo) {
        RequestCheckUtil.checkBaseInfoAdd(baseInfo);
        taskService.updateBaseInfo(baseInfo);
        return AjaxResult.success();
    }

    @PostMapping("/delBaseInfo")
    public AjaxResult delBaseInfo(@RequestBody TBaseInfo baseInfo) {
        baseInfo.setIsDelete(1);
        taskService.updateBaseInfo(baseInfo);
        return AjaxResult.success();
    }


    @PostMapping("/selectBaseInfo")
    public AjaxResult selectBaseInfo(@RequestBody TBaseInfoDto baseInfo) {
        AjaxResult tBaseInfos = taskService.selectBaseInfo(baseInfo);
        return tBaseInfos;
    }

//-----------------------------开始任务-------------------------------------

    /**
     * 添加基础信息
     *
     * @param tTaskInfo
     * @return
     */
    @PostMapping("/addTaskInfo")
    public AjaxResult addTaskInfo(@RequestBody TTaskInfoDto tTaskInfo) {
        RequestCheckUtil.checkTaskInfoAdd(tTaskInfo);
        taskService.addTaskInfo(tTaskInfo);
        return AjaxResult.success();
    }


    @PostMapping("/updateTaskInfo")
    public AjaxResult updateTaskInfo(@RequestBody TTaskInfoDto taskInfo) {
        RequestCheckUtil.checkTaskInfoAdd(taskInfo);
        taskService.updateTaskInfo(taskInfo);
        return AjaxResult.success();
    }

    @PostMapping("/delTaskInfo")
    public AjaxResult delTaskInfo(@RequestBody TTaskInfoDto baseInfo) {
        baseInfo.setIsDelete(1);
        taskService.updateTaskInfo(baseInfo);
        return AjaxResult.success();
    }


    /**
     * 获取审核任务列表
     * @param
     * @return
     */
    @PostMapping("/selectTaskInfo")
    public AjaxResult selectTaskInfo(@RequestBody ConditionReq req) {
        AjaxResult tBaseInfos = taskService.selectTaskInfo(req);
        return tBaseInfos;
    }
    @ApiOperation("首页-1-综合；2-新发布；3-价格；4-人气；5-图文任务")
    @PostMapping("/getHomeTaskByType")
    public AjaxResult getHomeTaskByType(@RequestBody ConditionReq req) {
        AjaxResult result = userService.getTaskByType(req);
        return result;
    }


    @ApiOperation("查看任务详情")
    @PostMapping("/sysTaskInfo")
    public AjaxResult sysTaskInfo(@RequestBody ConditionReq req) {
        AjaxResult result = taskService.sysTaskInfo(req);
        return result;
    }

    /**
     * 获取待审核任务列表
     * @param taskInfo
     * @return
     */
    @PostMapping("/selectForAuditTask")
    public AjaxResult selectForAuditTask(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.auditTaskInfo(taskInfo);
        return tBaseInfos;
    }

    /**
     * 审核用户提交任务
     * @param taskInfo
     * @return
     */
    @PostMapping("/auditTaskInfo")
    public AjaxResult auditTaskInfo(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.auditTaskInfo(taskInfo);
        return tBaseInfos;
    } /**
     * 审核用户提交任务
     * @param taskInfo
     * @return
     */
    @PostMapping("/auditSysTaskInfo")
    public AjaxResult auditSysTaskInfo(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.auditSysTaskInfo(taskInfo);
        return tBaseInfos;
    }

    /**
     * 审核上下架
     * @param taskInfo
     * @return
     */
    @PostMapping("/auditShelfTaskInfo")
    public AjaxResult auditShelfTaskInfo(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.auditShelfTaskInfo(taskInfo);
        return tBaseInfos;
    }


    /**
     * 获取任务标签
     */
        @PostMapping("/getBaseTag")
    public AjaxResult getBaseTag(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.getBaseTag( taskInfo);
        return tBaseInfos;
    }


    /**
     * 获取用户提交的任务
     */
    @PostMapping("/getUserTask")
    public AjaxResult getUserTask(@RequestBody TTaskInfoDto taskInfo) {
        AjaxResult tBaseInfos = taskService.getUserTask( taskInfo);
        return tBaseInfos;
    }

    /**
     * 获取用户提交的任务
     */
    @PostMapping("/getAuditUserInfo")
    public AjaxResult getAuditUserInfo(@RequestBody TTaskInfoDto taskInfo) {
        if (taskInfo.getTaskId()==null) {
            throw new ServiceException("任务id不能为空");
        }if (taskInfo.getUserId()==null) {
            throw new ServiceException("任务截取对象不能为空");
        }
        AjaxResult tBaseInfos = taskService.getAuditUserInfo( taskInfo);
        return tBaseInfos;
    }
}
